package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Client;
import cn.wolfcode.crm.domain.InsureInfo;
import cn.wolfcode.crm.query.AttendanceQueryObject;
import cn.wolfcode.crm.query.ClaimsClientDetailsQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICaseInfoService;
import cn.wolfcode.crm.service.IClaimsClientDetailsService;
import cn.wolfcode.crm.service.IClientService;
import cn.wolfcode.crm.service.IInsureInfoService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collections;
import java.util.List;

@Controller
@RequestMapping("/claimsClientDetails")
public class ClaimsClientDetailsController {
    @Autowired
    private IClientService clientService;

    @Autowired
    private IClaimsClientDetailsService claimsClientDetailsService;

    @RequestMapping("/view")
    public String view() {

        return "/compensate/claimsClientDetails";
    }


    @RequestMapping("/query")
    @ResponseBody
    public Object query(ClaimsClientDetailsQueryObject qo) {
        //根据用户名查询出客户的id
        String name = qo.getKeyword();
        if (name != null && name != "") {
            System.out.println("高级查询参数:  " + name);
            Long clientId = clientService.selectIdByName(name);
            if (clientId == null) {
                return new PageResult(0, Collections.emptyList());
            }
            qo.setClientId(clientId);
        }

        return claimsClientDetailsService.query(qo);
    }

    @RequestMapping("/validateName")
    @ResponseBody
    public boolean validateName(String keyword) {
        Long clientId = clientService.selectIdByName(keyword);
        if (clientId == null) {
            return false;
        } else {
            return claimsClientDetailsService.selectByClientId(clientId) != null ? true : false;
        }

    }


}
